var t = getApp();
Page({
    data: {
        index: 0
    },
    click:function(){
      wx.switchTab({
        url: '../hall/hall',
      })
    },
    onLoad: function() {
      this.setData({
        switch:t.globalData.switch,
        switch1:t.globalData.switch1
      })
        wx.showLoading({
            title: "数据加载中..."
        });
        var e = this;
        this.setData({
            openid: t.globalData.openid
        });
        var a = [], o = wx.cloud.database({
            env: "tangtang-0gijvqhs3851baf6"
        });
        o.collection("loseThing").where({
            _openid: this.data.openid
        }).get({
            success: function(t) {
                for (var o = 0; o < t.data.length; o++) a.push(t.data[o]);
                e.setData({
                    list: a
                });
            }
        });
        var n = [];
        o.collection("seekThing").where({
            _openid: this.data.openid
        }).get({
            success: function(t) {
                for (var a = 0; a < t.data.length; a++) n.push(t.data[a]);
                e.setData({
                    list1: n
                }), wx.hideLoading();
            }
        });
    },
    update: function(t) {
        var e = this, a = wx.cloud.database({
            env: "tangtang-0gijvqhs3851baf6"
        });
        "认领中" == this.data.list[t.currentTarget.dataset.index].upshot ? a.collection("loseThing").where({
            _id: this.data.list[t.currentTarget.dataset.index]._id
        }).update({
            data: {
                upshot: "已认领"
            }
        }).then(function(t) {
            e.onLoad(), wx.showToast({
                title: "纺院社区:修改成功",
                icon: "none",
                image: "",
                duration: 3e3,
                mask: !1
            });
        }).catch(function(t) {
            wx.showToast({
                title: "纺院社区：修改失败，请重试或者反馈管理员",
                icon: "none",
                image: "",
                duration: 3e3,
                mask: !1
            });
        }) : a.collection("loseThing").where({
            _id: this.data.list[t.currentTarget.dataset.index]._id
        }).update({
            data: {
                upshot: "认领中"
            }
        }).then(function(t) {
            e.onLoad(), wx.showToast({
                title: "纺院社区：修改成功",
                icon: "none",
                image: "",
                duration: 3e3,
                mask: !1
            });
        }).catch(function(t) {
            wx.showToast({
                title: "纺院社区：修改失败，请重试或者反馈管理员",
                icon: "none",
                image: "",
                duration: 3e3,
                mask: !1
            });
        });
    },
    delete: function(t) {
        var e = this;
        wx.showModal({
            title: "确认删除",
            content: "是否删除该发布任务？",
            showCancel: !0,
            cancelColor: "#000000",
            confirmText: "删除",
            confirmColor: "#576B95",
            success: function(a) {
                a.confirm && (wx.showLoading({
                    title: "请稍后"
                }),
                wx.cloud.deleteFile({
                  fileList:[e.data.list[t.currentTarget.dataset.index].bigImg],
                }).then(res => {
                  console.log("删除云图片成功")
                }).catch(error => {
                  console.log("删除云图片失败")
                })
                ,
                 wx.cloud.database({
                    env: "tangtang-0gijvqhs3851baf6"
                }).collection("loseThing").where({
                    _id: e.data.list[t.currentTarget.dataset.index]._id
                }).remove().then(function(t) {
                    wx.hideLoading(), e.onLoad(), wx.showToast({
                        title: "删除成功",
                        icon: "none",
                        image: "",
                        duration: 2e3,
                        mask: !1
                    });
                }).catch(function(t) {
                    wx.hideLoading(), wx.showToast({
                        title: "纺院社区：删除失败，请联系管理员",
                        icon: "none",
                        image: "",
                        duration: 2e3,
                        mask: !1
                    });
                }
                ));
            }
        });
    },
    update1: function(t) {
        var e = this;
        wx.cloud.database({
            env: "tangtang-0gijvqhs3851baf6"
        }).collection("seekThing").where({
            _id: this.data.list1[t.currentTarget.dataset.index]._id
        }).update({
            data: {
                upshot: "寻回"
            }
        }).then(function(t) {
            e.onLoad(), wx.showToast({
                title: "纺院社区：修改成功",
                icon: "none",
                image: "",
                duration: 3e3,
                mask: !1
            });
        }).catch(function(t) {
            wx.showToast({
                title: "纺院社区：修改失败，请重试或者反馈管理员",
                icon: "none",
                image: "",
                duration: 3e3,
                mask: !1
            });
        });
    },
    delete1: function(t) {
        var e = this;
        wx.showModal({
            title: "确认删除",
            content: "是否删除该发布任务？",
            showCancel: !0,
            cancelColor: "#000000",
            confirmText: "删除",
            confirmColor: "#576B95",
            success: function(a) {
                a.confirm && (wx.showLoading({
                    title: "请稍后"
                }), 
                
                wx.cloud.deleteFile({
                  fileList:[e.data.list1[t.currentTarget.dataset.index].bigImg]
                }).then(res => {
                  console.log("删除云图片成功")
                }).catch(error => {
                  console.log("删除云图片失败")
                })




                
                
                
                ,
                wx.cloud.database({
                    env: "tangtang-0gijvqhs3851baf6"
                }).collection("seekThing").where({
                    _id: e.data.list1[t.currentTarget.dataset.index]._id
                }).remove().then(function(t) {
                    wx.hideLoading(), e.onLoad(), wx.showToast({
                        title: "删除成功",
                        icon: "none",
                        image: "",
                        duration: 2e3,
                        mask: !1
                    });
                }).catch(function(t) {
                    wx.hideLoading(), wx.showToast({
                        title: "纺院社区：删除失败，请联系管理员",
                        icon: "none",
                        image: "",
                        duration: 2e3,
                        mask: !1
                    });
                }));
            }
        });
    },
    index: function() {
        0 == this.data.index ? this.setData({
            index: 1
        }) : this.setData({
            index: 0
        });
    }
});